;变量的定义
AnyKeyPressed := false
shiftKeyDown:= false
 
SetCapsLockState, AlwaysOff
;Esc 映射ESC
Capslock::
    ; 如果是 IDEA 先切换输入法、再按ESC
    if WinActive("ahk_exe Code.exe"){
        Send {Blind}{Esc Down}{Esc Up}
        SwitchIME(0x04090409) ;; 切換為英文輸入
        Send {Blind}{Esc Down}{Esc Up}
        Return
    }
return

; 输入法切换
SwitchIME(dwLayout){
    HKL:=DllCall("LoadKeyboardLayout", Str, dwLayout, UInt, 1)
    ControlGetFocus,ctl,A
    SendMessage,0x50,0,HKL,%ctl%,A
}
return
~Shift::
{
    shiftKeyDown:=true
    return
}
~*::
{
    ; 如果Shift键被按下
    if (shiftKeyDown)
    {
        AnyKeyPressed:=true
        ; 获取当前按下的键
        ; Key := SubStr(A_ThisHotkey, 3)
        ; MsgBox Shift + %Key% pressed.
    }
    return
}
~RShift Up::

    shiftKeyDown:=false
    if( !AnyKeyPressed ) {
        SwitchIME(00000804) ;; 切換為中文輸入
    }
    AnyKeyPressed:=false
    ; ToolTip, cn, A_CaretX, A_CaretY + 20
return
; 
~LShift Up::

    shiftKeyDown:=false
    if( !AnyKeyPressed ) {
    SwitchIME(0x04090409) ;; 切換為英文輸入
    }
    AnyKeyPressed:=false
    ; ToolTip, en, A_CaretX, A_CaretY + 20
return
;